package com.liyiqing.secondhandmall.productservice.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.liyiqing.secondhandmall.productservice.entity.ProductCategoryEntity;
import com.liyiqing.secondhandmall.productservice.service.ProductCategoryService;
import com.liyiqing.commonservice.utils.PageUtils;
import com.liyiqing.commonservice.utils.R;

import javax.annotation.Resource;


/**
 * 一级分类
 *
 * @author LiYiQing
 * @email 1570865668@qq.com
 * @date 2022-02-18 23:36:20
 */
@Slf4j
@RestController
@RequestMapping("productService/productCategory")
public class ProductCategoryController {
    @Resource
    private ProductCategoryService productCategoryService;

    //redis工具
    @Resource
    private StringRedisTemplate stringRedisTemplate;


    /**
     * 查找所有一级分类目录
     */
    @RequestMapping("/selectAllProductCategory")
    public R selectAllProductCategory(){
        return productCategoryService.selectAllProductCategory();
    }




    /**
     * 信息
     */
    @RequestMapping("/info/{catalogId}")
    public R info(@PathVariable("catalogId") Long catalogId){
		ProductCategoryEntity productCategory = productCategoryService.getById(catalogId);

        return R.ok().put("productCategory", productCategory);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ProductCategoryEntity productCategory){
		productCategoryService.save(productCategory);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ProductCategoryEntity productCategory){
		productCategoryService.updateById(productCategory);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] catalogIds){
		productCategoryService.removeByIds(Arrays.asList(catalogIds));

        return R.ok();
    }

}
